package com.entity.generate;

import java.sql.JDBCType;

/**
 * @ClassName TypeUtil
 * @Description TODO
 * @Author 谭庆伟
 * @Date 2020/8/22 15:31
 * @Version 1.0
 **/
public class TypeUtil {
    private static final String javaStr = "String\n" +
            "String\n" +
            "String\n" +
            "java.math.BigDecimal\n" +
            "java.math.BigDecimal\n" +
            "boolean\n" +
            "boolean\n" +
            "byte\n" +
            "short\n" +
            "int\n" +
            "long\n" +
            "float\n" +
            "double\n" +
            "double\n" +
            "byte[]\n" +
            "byte[]\n" +
            "byte[]\n" +
            "java.sql.Date\n" +
            "java.sql.Time\n" +
            "java.sql.Timestamp\n" +
            "Clob\n" +
            "Blob\n" +
            "Array\n" +
            "mapping of underlying type\n" +
            "Struct";
    private static final String jdbcStr = "CHAR\n" +
            "VARCHAR\n" +
            "LONGVARCHAR\n" +
            "NUMERIC\n" +
            "DECIMAL\n" +
            "BIT\n" +
            "BOOLEAN\n" +
            "TINYINT\n" +
            "SMALLINT\n" +
            "INTEGER\n" +
            "BIGINT\n" +
            "REAL\n" +
            "FLOAT\n" +
            "DOUBLE\n" +
            "BINARY\n" +
            "VARBINARY\n" +
            "LONGVARBINARY\n" +
            "DATE\n" +
            "TIME\n" +
            "TIMESTAMP\n" +
            "CLOB\n" +
            "BLOB\n" +
            "ARRAY\n" +
            "DISTINCT\n" +
            "STRUCT";
    public static String[] jdbcArr;
    public static String[] javaArr;
    static {
       jdbcArr = jdbcStr.split("\n");
       javaArr = javaStr.split("\n");
        //System.out.println(javaArr.length);
        //System.out.println(jdbcArr.length);
    }
    public static String getJavaType(int jdbcType){
        JDBCType jdbcType1 = JDBCType.valueOf(jdbcType);
        String jdbcName = jdbcType1.getName().toLowerCase();//全以小写对比
        String javaType = "";

        for (int i = 0; i < jdbcArr.length; i++) {
            if(jdbcArr[i].toLowerCase().equals(jdbcName)){
                javaType = javaArr[i];
                break;
            }
        }

        return javaType;

    }
}
